# coding=utf-8
def reduce2(function, iterable, initializer=None):
    it = iter(iterable)
    if initializer is None:
        try:
            initializer = next(it)
        except StopIteration:
            raise TypeError('reduce() of empty sequence with no initial value')
    x = initializer
    for y in it:
        x = function(x, y, z=None)
    return x

def f(x, y, z=None):
    print 'x', x, 'y', y
    sum = x + y
    return sum

if __name__ == '__main__':
    print reduce2(f, range(1, 5), 100)

